package com.interview.controller;

import com.interview.common.Result;
import com.interview.common.ResultMessage;
import com.interview.common.StatusCode;
import com.interview.entity.Schedule;
import com.interview.entity.GroupInfo;
import com.interview.entity.Schedule;
import com.interview.service.DataDownLoadService;
import com.interview.service.ScheduleService;
import com.interview.service.GroupInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

@RestController
@RequestMapping("groupInfo")
public class GroupInfoController {
    @Autowired
    private GroupInfoService groupInfoService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private DataDownLoadService dataDownLoadService;

//    @PostMapping("generateDrawLotsProcess")
//    public Result generateDrawLotsProcess() {
//        List<GroupInfo> allGroupInfo = groupInfoService.getAllGroupInfo();
//        List<Schedule> allSchedules = new LinkedList<>();
//        for (GroupInfo groupInfo : allGroupInfo) {
//            List<Schedule> groupDrawLotsSchedules = groupInfoService.generateDrawLotsProcess(groupInfo);
//            for (Schedule groupDrawLotsSchedule : groupDrawLotsSchedules) {
//                allSchedules.add(groupDrawLotsSchedule);
//            }
//        }
//        scheduleService.saveSchedule(allSchedules);
//        return new Result(true, StatusCode.OK, ResultMessage.OPERATION_SUCCESS,null);
//    }

    @PostMapping("getAvailableDownLoadGroupIds")
    public Result getAvailableDownLoadGroupIds() {
        List<GroupInfo> availableDownLoadGroupIds = dataDownLoadService.getAvailableDownLoadGroupIds();
        return new Result(true, StatusCode.OK, ResultMessage.OPERATION_SUCCESS,availableDownLoadGroupIds);
    }

    @PostMapping("getGroupInfo")
    public Result getGroupInfo() {
        List<GroupInfo> groupInfo = groupInfoService.getAllGroupInfo();
        if (groupInfo.size()>0){
            return new Result(true, StatusCode.OK, ResultMessage.OPERATION_SUCCESS,groupInfo);
        }else {
            return new Result(false, StatusCode.ERROR, ResultMessage.OPERATION_FAILED,null);
        }
    }
}
